package cn.example.demo.common.db.wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 条件构造器，重写字符串转换方法
 *
 * @author Lizuxian
 * @create 2022/4/17 9:12
 */
public class CustomQueryWrapper<T> extends QueryWrapper<T> {
    /**
     * 关联查询构造器
     */
    private final List<JoinBuilder> joinBuilder = new ArrayList<>();

    /**
     * 获取 columnName
     *
     * @param column
     */
    @Override
    protected String columnToString(String column) {
        return StringUtils.camelToUnderline(column);
    }

    public static <T> CustomQueryWrapper<T> query() {
        return new CustomQueryWrapper<T>();
    }

    /**
     * 关联查询构造
     *
     * @param builder
     * @return
     */
    public CustomQueryWrapper<T> addJoin(JoinBuilder builder) {
        this.joinBuilder.add(builder);
        return this;
    }

    public List<JoinBuilder> getJoinBuilder() {
        return joinBuilder;
    }

    /**
     * 排序
     *
     * @param sorts
     * @return
     */
//    public QueryWrapper<T> sort(List<Sort> sorts) {
//        if (!CollectionUtils.isEmpty(sorts)) {
//            sorts.forEach(item -> {
//                orderBy(item.getSortField() != null, "asc".equals(item.getSortValue()), item.getSortField());
//            });
//        }
//        return this;
//    }
}
